//
// Created by denglibin on 2021/6/2.
//

#include "game_window.h"
#include "draw.h"
int main_demo5(int argc, char** argv){
    GameWindow * gameWindow = GameWindowCreate(800, 600, "demo5");
    gameWindow->scene_index = 0;
    gameWindow->run = 1;
    gameWindow->start = SDL_GetTicks();
    while (gameWindow->run)
    {//主消息循环
        uint32_t  begin = SDL_GetTicks();
        gameWindow->interval = (int)(begin - gameWindow->start);
        gameWindow->start = begin;
        //绘制
        draw(gameWindow);
        uint32_t  end = SDL_GetTicks();
        uint32_t  cost = end - begin;
        uint32_t per_frame_time = 1000 / gameWindow->fps;//每一帧耗时ms
        if (per_frame_time > cost){
            //减去循环体耗时，得到还应休眠的时间
            SDL_Delay(per_frame_time - cost);
        }

    }
    GameWindowFree(gameWindow);
}